package org.java;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DoLoop {
	final static int count = 10000000;

	public static void main(String[] argc) {

		List<Integer> list = new ArrayList<Integer>();
		long startTime = System.currentTimeMillis();
		for (int i = 0; i < 10; i++) {
			list.clear();
			for (int j = 0; j < count; j++) {
				list.add(j);
			}			
		}
		System.out.println("list add:"
				+ (System.currentTimeMillis() - startTime));

		startTime = System.currentTimeMillis();
		for (int i = 0; i < 10; i++) {
			for (int j = 0, len = list.size(); j < len; j++) {
				list.get(j);
			}
		}
		System.out.println("list get:"
				+ (System.currentTimeMillis() - startTime));

		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		startTime = System.currentTimeMillis();
		for (int i = 1; i < 11; i++) {
			for (int j = 0; j < count; j++) {
				map.put(j, j);
			}
		}
		System.out.println("map put:"
				+ (System.currentTimeMillis() - startTime));

		startTime = System.currentTimeMillis();
		for (int i = 0; i < 10; i++) {
			for (int j = 0, len = map.size(); j < len; j++) {
				map.get(j);
			}
		}
		System.out.println("map get:"
				+ (System.currentTimeMillis() - startTime));
		return;
	}
}
